package com.infore.airsupervise.utils;

import com.infore.airsupervise.R;
import com.infore.airsupervise.app.StatusConst;
import com.infore.airsupervise.bean.AirStationE.AirLevel;

/**
 * 空气污染程度帮助类
 */

public class AirLevelUtil {

    public static AirLevel getAirLevelObj(int type, double value) {
        return getAirLevelObj(type, value, true);
    }

    public static String getStationType (int type){
        String typeName = null;
        switch (type){
            case StatusConst.STATION_MICRO :
                typeName = "微型站";
                break ;
            case StatusConst.STATION_NATION :
                typeName = "国控站";
                break ;
            case StatusConst.STATION_POLLUTION:
                typeName = "污染源";
                break ;
            default:
                typeName = "暂无";
        }
        return typeName;
    }

    /**
     * 排名列表中根据等级获取图标
     * @param level
     * @return
     */
    public static int getRealRankIcon(int level){
        switch (level){
            case  0 :
                return R.drawable.site1;

            case  1 :
                return (R.drawable.site2);

            case  2 :
                return (R.drawable.site3);

            case  3 :
                return (R.drawable.site4);

            case  4 :
                return (R.drawable.site5);

            case  5 :
                return (R.drawable.site6);
            case  6 :
                return (R.drawable.site7);
            default:
                return (R.drawable.site_off);
        }
    }

    /**
     * 获取不同站点类型的图标
     * @param labeltype
     * @param level
     * @return
     */
    public static int getLabelIcon( int labeltype,int level){

        switch (labeltype){
            case StatusConst.STATION_NATION :
                switch (level){
                    case  0 :
                       return R.drawable.national_01;

                    case  1 :
                        return (R.drawable.national_02);

                    case  2 :
                        return (R.drawable.national_03);

                    case  3 :
                        return (R.drawable.national_04);

                    case  4 :
                        return (R.drawable.national_05);

                    case  5 :
                        return (R.drawable.national_06);
                    case  6 :
                        return (R.drawable.national_07);
                    default:
                        return (R.drawable.national_off_line);

                }

            case StatusConst.STATION_POLLUTION :
                switch (level){
                    case  0 :
                        return (R.drawable.pollution_01);

                    case  1 :
                        return (R.drawable.pollution_02);

                    case  2 :
                        return (R.drawable.pollution_03);

                    case  3 :
                        return (R.drawable.pollution_04);

                    case  4 :
                        return (R.drawable.pollution_06);

                    case  5 :
                        return (R.drawable.pollution_06);

                    case  6 :
                        return (R.drawable.pollution_07);

                    default:
                        return (R.drawable.pollution_01);

                }

            case StatusConst.STATION_MICRO :
                switch (level){
                    case  0 :
                        return (R.drawable.micro_01);

                    case  1 :
                        return (R.drawable.micro_02);

                    case  2 :
                        return (R.drawable.micro_03);

                    case  3 :
                        return (R.drawable.micro_04);

                    case  4 :
                        return (R.drawable.micro_05);

                    case  5 :
                        return (R.drawable.micro_06);

                    case  6 :
                        return (R.drawable.micro_07);

                    default:
                        return (R.drawable.micro_off_line);

                }
                default: return R.drawable.micro_off_line;
        }
    }

    /**
     * 获取污染等级对象
     * @param type
     * @param value
     * @param online
     * @return
     */
    public static AirLevel getAirLevelObj(int type, double value, boolean online) {
        System.out.println(type);
        System.out.println(value);
        System.out.println(online);
        AirLevel airLevel =null;
        if (!online) {
            airLevel = new AirLevel(R.color.station_off_line , -1 ,"离线" , R.drawable.off_line ,R.drawable.night_off_line);

            return airLevel ;
        }
        switch (type) {
            case StatusConst.AIR_TYPE_AQI:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 50) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 100) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 150) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 200) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 300) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 500) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6, R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_NO2:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 100) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 200) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 700) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 1200) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 2340) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 3840) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_CO:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 5) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 10) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 35) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 60) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 90) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 150) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_O3:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 160) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 200) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 300) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 400) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 800) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 1200) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                    break;
            case StatusConst.AIR_TYPE_PM10:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 50) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 150) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 250) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 350) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 420) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 600) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_PM25:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 35) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 75) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 115) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 150) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else if (value <= 250) {
                    airLevel  = new AirLevel(R.color.air_level_5, 5, "重度污染",R.drawable.level5 , R.drawable.night_06);
                } else if (value <= 500) {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6 , R.drawable.night_07);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_SO2:
                if (value <= 0) {
                    airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1 , R.drawable.night_01);
                } else if (value <= 150) {
                    airLevel  = new AirLevel(R.color.air_level_1, 1, "优",R.drawable.level2  , R.drawable.night_02);
                } else if (value <= 500) {
                    airLevel  = new AirLevel(R.color.air_level_2, 2, "良",R.drawable.level3  , R.drawable.night_03);
                } else if (value <= 650) {
                    airLevel  = new AirLevel(R.color.air_level_3, 3, "轻度污染",R.drawable.level4 , R.drawable.night_04);
                } else if (value <= 800) {
                    airLevel  = new AirLevel(R.color.air_level_4, 4, "中度污染",R.drawable.level4 , R.drawable.night_05);
                } else  {
                    airLevel  = new AirLevel(R.color.air_level_6, 6, "严重污染" ,R.drawable.level6,  R.drawable.night_07);
                }
                break;
            case StatusConst.AIR_TYPE_VOC:
                airLevel  = new AirLevel(R.color.air_level_0, 0, String.valueOf(value),R.drawable.level1 , R.drawable.night_01);
                break;
            default:
                airLevel  = new AirLevel(R.color.air_level_0, 0, "0值",R.drawable.level1,R.drawable.night_01);
                break;
        }

        return airLevel;
    }

    /**
     * 获取因子类型
     * @param str_type
     * @return
     */
    public static int getType(String str_type){
        if(str_type.equals("PM2.5")){
            return StatusConst.AIR_TYPE_PM25;
        }else if(str_type.equals("PM10")){
            return StatusConst.AIR_TYPE_PM10;
        }else if(str_type.equals("SO₂")){
            return StatusConst.AIR_TYPE_SO2;
        }else if(str_type.equals("NO₂")){
            return StatusConst.AIR_TYPE_NO2;
        }else if(str_type.equals("CO")){
            return StatusConst.AIR_TYPE_CO;
        }else if(str_type.equals("O₃")){
            return StatusConst.AIR_TYPE_O3;
        }else if(str_type.equals("VOC")){
            return StatusConst.AIR_TYPE_VOC;
        }else {
            return StatusConst.AIR_TYPE_AQI;
        }
    }


    public static int getFactorLevelColor(int flag ,int type , double value){
        if(value<=0){
            if(flag == -1) {
                return R.color.air_level_0;
            }else {
                return android.R.color.white;
            }
        }
        switch (type){
            case StatusConst.AIR_TYPE_AQI :
                if (value <= 50) {
                    return R.color.air_level_1;
                } else if (value <= 100) {
                    return R.color.air_level_2;
                } else if (value <= 150) {
                    return R.color.air_level_3;
                } else if (value <= 200) {
                    return R.color.air_level_4;
                } else if (value <= 300) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_CO:
                if (value <= 5) {
                    return R.color.air_level_1;
                } else if (value <= 10) {
                    return R.color.air_level_2;
                } else if (value <= 35) {
                    return R.color.air_level_3;
                } else if (value <= 60) {
                    return R.color.air_level_4;
                } else if (value <= 90) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_NO2:
                if (value <= 100) {
                    return R.color.air_level_1;
                } else if (value <= 200) {
                    return R.color.air_level_2;
                } else if (value <= 700) {
                    return R.color.air_level_3;
                } else if (value <= 1200) {
                    return R.color.air_level_4;
                } else if (value <= 2340) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_O3:
                if (value <= 160) {
                    return R.color.air_level_1;
                } else if (value <= 200) {
                    return R.color.air_level_2;
                } else if (value <= 300) {
                    return R.color.air_level_3;
                } else if (value <= 400) {
                    return R.color.air_level_4;
                } else if (value <= 800) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_PM10:
                if (value <= 50) {
                    return R.color.air_level_1;
                } else if (value <= 150) {
                    return R.color.air_level_2;
                } else if (value <= 250) {
                    return R.color.air_level_3;
                } else if (value <= 350) {
                    return R.color.air_level_4;
                } else if (value <= 420) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_PM25:
                if (value <= 35) {
                    return R.color.air_level_1;
                } else if (value <= 75) {
                    return R.color.air_level_2;
                } else if (value <= 115) {
                    return R.color.air_level_3;
                } else if (value <= 150) {
                    return R.color.air_level_4;
                } else if (value <= 250) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            case StatusConst.AIR_TYPE_SO2:
                if (value <= 50) {
                    return R.color.air_level_1;
                } else if (value <= 150) {
                    return R.color.air_level_2;
                } else if (value <= 500) {
                    return R.color.air_level_3;
                } else if (value <= 650) {
                    return R.color.air_level_4;
                } else if (value <= 800) {
                    return R.color.air_level_5;
                } else  {
                    return R.color.air_level_6;
                }
            default:
                return android.R.color.white;
        }
    }

    public static int getFactorLevelColor(int type , double value){
        return getFactorLevelColor(-1 , type ,value);
    }

}





